﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dto;
using bus;
namespace HOANGVIET
{
    public partial class DSLopcs : Form
    {
        public DSLopcs(KetNoiDto ketnoi, int idcaphoc)
        {
            InitializeComponent();
            lophocBUS = new LOPHOCBus(ketnoi);
            lophocDTO = new LOPHOCdto();
            idcap = idcaphoc;
            lopDT = new DataTable();
        }
        #region bien
        LOPHOCBus lophocBUS;
        public LOPHOCdto lophocDTO;
        int idcap;

        DataTable lopDT;
        #endregion
        #region ham
        public void timiiemlop_ten(int idlop)
        {
            try
            {
                lopDT = new DataTable();
                lopDT = lophocBUS.LayBangTableTheoIDLOPHOC(idlop);
                dataGridViewX1.DataSource = lopDT;
            }
            catch (Exception)
            {
            }
        }
        public void timloptheoLoai()
        {
            try
            {
                lopDT = new DataTable();
                if (radioButton1.Checked == true)
                    lopDT = lophocBUS.laybangthaotrangthai_cap(idcap, 1);
                else
                    lopDT = lophocBUS.laybangthaotrangthai_cap(idcap, 2);
                dataGridViewX1.DataSource = lopDT;
            }
            catch (Exception)
            {
            }
        }
        public void loadForm()
        {
            DataTable dt = new DataTable();
            //
            dt = lophocBUS.LayBangTableTheoIDCAPHOC(idcap);
            //dt = lophocBUS.laybangthaotrangthai_cap(idcap,1);
            AutoCompleteStringCollection auto3 = new AutoCompleteStringCollection();
            comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            foreach (DataRow row in dt.Rows)
            {
                auto3.Add(row["TENLOP"].ToString());
            }
            comboBox1.AutoCompleteCustomSource = auto3;
            comboBox1.DataSource = dt;
            comboBox1.DisplayMember = "TENLOP";
            comboBox1.ValueMember = "IDLOPHOC";
        }
        #endregion
        #region su kien

        private void buttonX1_Click(object sender, EventArgs e)
        {
            lophocDTO = lophocBUS.LayBangDTo(dataGridViewX1.CurrentRow.Index, dataGridViewX1);
            this.Close();
        }

        private void DSLopcs_Load(object sender, EventArgs e)
        {
            try
            {
                loadForm();
                timloptheoLoai();
            }
            catch (Exception)
            {
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                timloptheoLoai();
            }
            catch (Exception)
            {


            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                timloptheoLoai();
            }
            catch (Exception)
            {


            }

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                timiiemlop_ten(int.Parse(comboBox1.SelectedValue.ToString()));
            }
            catch (Exception)
            {


            }

        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            lophocDTO = new LOPHOCdto();
            this.Close();
        }
        #endregion
    }
}
